package com.llmcu.source.javase.thread.basicusage;

import java.util.concurrent.TimeUnit;

/**
 * 线程的基本方法
 *
 * @author liuling
 * @date 2024/11/13 20:08
 */
public class BasicMethod {
    public static void main(String[] args) throws InterruptedException {
        // 0、准备工作：创建一个线程
        Thread thread = new Thread(()->{
            System.out.println(Thread.currentThread().getName()+"：我的id是："+
                    Thread.currentThread().getId()+"start to do something!");
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+":something finished!");
        });
        // 1、常用方法
        thread.setPriority(5);
        System.out.println("工作线程优先级为："+thread.getPriority());
        thread.setName("工作线程");

        System.out.println(Thread.currentThread().getName()+"准备休息1秒后开始做工");
        Thread.yield();
        Thread.sleep(1000);
        thread.start();
        Thread.sleep(1000);
        System.out.println("工作线程isInterrupted："+thread.isInterrupted());
        thread.interrupt();
        System.out.println("工作线程isInterrupted："+thread.isInterrupted());

    }
}
